package com.ruijie.autotest.log.validation.hangzhouxiruan;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.ruijie.autotest.log.core.validate.IValidator;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

import static com.ruijie.autotest.log.impl.validate.SqlExistingValidator.sqlExistingVerificationOf;
import static com.ruijie.autotest.log.impl.validate.SqlMappedExistingValidator.mappedVerification;

@SpringBootConfiguration
public class Config {
	@Bean
	public DataSource dataSource() {
		return new ComboPooledDataSource("remote");
	}

	@Bean
	public IValidator HTTP_TYPEValidator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.http_type", dataSource);
	}

	@Bean
	public IValidator URLValidator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.url", dataSource);
	}

	@Bean
	public IValidator SESSIONIDValidator(DataSource dataSource) {
		return mappedVerification("eg_http_log.session_id",
				String::toLowerCase,
				dataSource);
	}

	@Bean
	public IValidator NETSERVERPORT_WACODEValidator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.url", dataSource);
	}

	@Bean
	public IValidator NETWORK_APPValidator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.network_app", dataSource);
	}

	@Bean
	public IValidator IP_ADDRESSValidator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.ip_address", dataSource);
	}

	@Bean
	public IValidator PORTValidator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.port", dataSource);
	}

	@Bean
	public IValidator SRC_IPValidator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.src_ip", dataSource);
	}

	@Bean
	public IValidator SRC_IPV6Validator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.src_ipv6", dataSource);
	}

	@Bean
	public IValidator SRC_PORT_STARTValidator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.src_port_start", dataSource);
	}

	@Bean
	public IValidator SRC_PORT_ENDValidator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.src_port_end", dataSource);
	}

	@Bean
	public IValidator SRC_PORT_START_V6Validator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.src_port_start_v6", dataSource);
	}

	@Bean
	public IValidator SRC_PORT_END_V6Validator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.src_port_end_v6", dataSource);
	}

	@Bean
	public IValidator DST_IPValidator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.dst_ip", dataSource);
	}

	@Bean
	public IValidator DST_IPV6Validator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.dst_ipv6", dataSource);
	}

	@Bean
	public IValidator DST_PORTValidator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.dst_port", dataSource);
	}

	@Bean
	public IValidator DST_PORT_V6Validator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.dst_port_v6", dataSource);
	}

	@Bean
	public IValidator MACValidator(DataSource dataSource) {
		return mappedVerification("eg_http_log.mac",
				String::toUpperCase,
				dataSource);
	}

	@Bean
	public IValidator COLLECTION_EQUIPMENT_IDValidator(DataSource dataSource) {
		return mappedVerification("eg_http_log.collection_equipment_id",
				String::toUpperCase,
				dataSource);
	}

	@Bean
	public IValidator AP_MACValidator(DataSource dataSource) {
		return mappedVerification("eg_http_log.ap_mac",
				String::toUpperCase,
				dataSource);
	}

	@Bean
	public IValidator LONGITUDEValidator(DataSource dataSource) {
		return sqlExistingVerificationOf("s_location.longitude", dataSource);
	}

	@Bean
	public IValidator LATITUDEValidator(DataSource dataSource) {
		return sqlExistingVerificationOf("s_location.latitude", dataSource);
	}

	@Bean
	public IValidator CAPTURE_TIMEValidator(DataSource dataSource) {
		return sqlExistingVerificationOf("eg_http_log.capture_time", dataSource);
	}
}
